package com.lsj.text;

import com.alibaba.druid.pool.DruidDataSource;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.ResourceBundle;

public class MyTest {

    @Test
    public void jdbc(){
        ResourceBundle jdbc = ResourceBundle.getBundle("jdbc");
        //创建数据源对象
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setDriverClassName(jdbc.getString("jdbc.driver"));
        dataSource.setUrl(jdbc.getString("jdbc.url"));
        dataSource.setUsername(jdbc.getString("jdbc.username"));
        dataSource.setPassword(jdbc.getString("jdbc.password"));

        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        //设置数据源对象  知道数据库在哪
        jdbcTemplate.setDataSource(dataSource);

        //执行操作
        int row = jdbcTemplate.update("insert into role (name,`desc`)values(?,?)", "aaa", "对对对对");
        System.out.println(row);
    }
}
